#include "FPSTracker.hpp"

FPSTracker::FPSTracker ()
{
  fpstimer.restart();
  frameCount = 0;
  cumulativeFrameCount = 0;
  cumulativeTime = 0.01;  // avoid that nasty division by zero error
  storedFPS = 0.0;
}

void FPSTracker::FrameDrawn ()
{
  frameCount++;
  cumulativeFrameCount++;
}

double FPSTracker::GetFPS()
{
  if (fpstimer.getElapsedTime().asSeconds() < 1.0)
    return storedFPS;   // if the elapsed time is under 1 second, don't update the fps, just return the stored value

  storedFPS = frameCount / fpstimer.getElapsedTime().asSeconds();
  cumulativeTime += fpstimer.getElapsedTime().asSeconds();
  fpstimer.restart();
  frameCount = 0;
  return storedFPS;
}

double FPSTracker::GetCumulativeFPS() const
{
  return cumulativeFrameCount / cumulativeTime;
}


